package com.whw.fy.service.impl;

import com.whw.fy.entity.Message;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.whw.fy.mapper.EmergencyMapper;
import com.whw.fy.entity.Emergency;
import com.whw.fy.service.EmergencyService;

import java.text.ParseException;
import java.text.SimpleDateFormat;import java.util.List;

@Service
public class EmergencyServiceImpl implements EmergencyService {

    @Resource
    private EmergencyMapper emergencyMapper;

    @Override
    public Message deleteByPrimaryKey(Integer emergencyId) {
        return emergencyMapper.deleteByPrimaryKey(emergencyId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insert(Emergency record) {
        return emergencyMapper.insert(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insertSelective(Emergency record) {
        return emergencyMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectByPrimaryKey(Integer emergencyId) {
        return Message.success(null).add(emergencyMapper.selectByPrimaryKey(emergencyId));
    }

    @Override
    public Message updateByPrimaryKeySelective(Emergency record) throws ParseException {
        if (record.getEmergencyTimeToString() != null) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            record.setEmergencyTime(simpleDateFormat.parse(record.getEmergencyTimeToString()));
        }
        return emergencyMapper.updateByPrimaryKeySelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message updateByPrimaryKey(Emergency record) {
        return emergencyMapper.updateByPrimaryKey(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectAll() {
        return Message.success(null).add(emergencyMapper.selectAll());
    }


    @Override
    public int batchInsert(List<Emergency> list) {
        return emergencyMapper.batchInsert(list);
    }

    @Override
    public Message selectByEmergencyClazzIdAndEmergencyClazzSkcd(int clazzId, int clazzSkcd) {
        return Message.success(null).add(emergencyMapper.selectByEmergencyClazzIdAndEmergencyClazzSkcd(clazzId, clazzSkcd));
    }

    @Override
    public Message selectAllByEmergencyClazzIdAndEmergencyStudentIdAndEmergencyClazzSkcd(Integer emergencyClazzId, Integer emergencyStudentId, Integer emergencyClazzSkcd) {
        return Message.success(null).add(emergencyMapper.selectAllByEmergencyClazzIdAndEmergencyStudentIdAndEmergencyClazzSkcd(emergencyClazzId,emergencyStudentId,emergencyClazzSkcd));
    }

    @Override
    public Message selectAllByEmergencyMold(Integer emergencyMold) {
        return Message.success(null).add(emergencyMapper.selectAllByEmergencyMold(emergencyMold));
    }


}


